package process

import (
	"github.com/shopspring/decimal"
	"matching/engine"
	"matching/errcode"
	"matching/middleware/cache"
	"matching/model"
)

/**
  创建一个连续竞价类型的交易引擎交易对
  需满足交易对名称、开盘价
 */
func CreateEngine(symbol string,price decimal.Decimal,coinScale int32,baseCoinScale int32) errcode.ErrorCode  {
	//判断是否已经创建过
	if engine.ChanMap[symbol]!=nil {
		//已经启动过
		return errcode.Started
	}
	engine.ChanMap[symbol]=make(chan model.Order,100)
	// 开启处理订单的通道
	go engine.Run(symbol,price,coinScale,baseCoinScale)
	cache.SaveSymbol(symbol)
	cache.SavePrice(symbol,price)
	return errcode.Success
}
